#include <iostream>

struct request // 涨薪请求
{
    int money;
};

class Manger // 抽象上级
{
protected:
    std::string name;
    Manger *m; // 直接上级的指针
public:
    Manger(const std::string &name) : name(name) {}
    void SetManfer(Manger *m) // 设置你的上级
    {
        this->m = m;
    }
    virtual void GetRequest(request *r) = 0;
};

class CommonManger : public Manger // 普通经理
{
public:
    using Manger::Manger;
    void GetRequest(request *r)
    {
        if (r->money <= 500)
        {
            std::cout << name << "批准了" << r->money << "涨薪请求" << std::endl;
        }
        else
        {
            m->GetRequest(r);
        }
    }
};

class Major : public Manger // 总监
{
public:
    using Manger::Manger;
    void GetRequest(request *r)
    {
        if (r->money > 500 && r->money <= 1000)
        {
            std::cout << name << "批准了" << r->money << "涨薪请求" << std::endl;
        }
        else
        {
            m->GetRequest(r);
        }
    }
};

class GeneralManger : public Manger // 总经理
{
public:
    using Manger::Manger;
    void GetRequest(request *r)
    {
        if (r->money > 1000)
        {
            std::cout << name << "批准了" << r->money << "涨薪请求" << std::endl;
        }
    }
};

int main()
{
    Manger *m1 = new CommonManger("张经理");
    Manger *m2 = new Major("李总监");
    Manger *m3 = new GeneralManger("王总");

    // 形成责任链
    m1->SetManfer(m2);
    m2->SetManfer(m3);

    request *r = new request;
    r->money = 1500;
    m1->GetRequest(r); // 把请求给普通经理
    return 0;
}